﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.UI;
using UnityEngine;

[CustomEditor(typeof(TextExtend))]
public class TextExtendEditor : GraphicEditor
{
    private TextExtend _inlineText;
    SerializedProperty m_Text;
    SerializedProperty cachetext;
    GUIContent _outputGUIContent, _inputGUIContent;
    private string _lastText;
    SerializedProperty m_FontData;
    protected override void OnEnable()
    {
        base.OnEnable();
        _lastText = "";
        m_Text = serializedObject.FindProperty("m_Text");
        cachetext = serializedObject.FindProperty("cacheText");
        _outputGUIContent = new GUIContent("Output Text");
        _inputGUIContent = new GUIContent("Input Text");
        _inlineText = (TextExtend)target;
        m_FontData = serializedObject.FindProperty("m_FontData");

    }
    public override void OnInspectorGUI()
    {

        serializedObject.Update();
        EditorGUILayout.PropertyField(cachetext, _inputGUIContent);
        GUI.enabled = false;
        EditorGUILayout.PropertyField(m_Text, _outputGUIContent);
        GUI.enabled = true;
        EditorGUILayout.PropertyField(m_FontData);
        AppearanceControlsGUI();
        RaycastControlsGUI();
        serializedObject.ApplyModifiedProperties();
        //更新字符
        if (_inlineText != null && _lastText != cachetext.stringValue)
        {
            _inlineText.text = cachetext.stringValue;
            _lastText = cachetext.stringValue;

        }
    }
}
